
// 专门处理影片相关的接口
var express = require('express');
var router = express.Router();
var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://127.0.0.1:27017/';
// 获取影片列表  location:3000/api/film/list
router.get('/list', function(req, res) {
    var phone = req.query.phone;
    var code = req.query.code;
    var results = {};
    MongoClient.connect(url, { useNewUrlParser: true }, function (err, client) {
        if (err) {
            results.code = -1;
            results.msg = '数据连接失败';
            res.json(results);
            return;
        }
        var db = client.db('vue-project');
        db.collection('users').find({
            phone: phone,
            code: code
        }).toArray(function (err, data) {
            if (err) {
                results.code = -1;
                results.msg = '查询失败';
            } else if (data.length <= 0) {
                results.code = -1;
                results.msg = "用户名或密码错误";
            } else {
                results.code = 0;
                results.msg = '登录成功';
            }
            client.close();
            res.json(results);
        })
    });
})
module.exports = router;
